package cn.neu.leon.util;

import java.util.Calendar;

public class PostTime {
	public static String format(String str)
	{
		str = str.substring(0,str.length()-1);//将从html页面中获取的发布时间字符串中的&nbsp;去掉
		String result;
		if(str.contains(" "))
		{
			String time[] = str.split(" ");
			if(time[0].equals("今天"))
			{
				Calendar ca =Calendar.getInstance();
				 int year = ca.get(Calendar.YEAR);//获取年份
			     int month=ca.get(Calendar.MONTH)+1;//获取月份
			     int day=ca.get(Calendar.DATE);//获取日
			  
			     result = year+"-"+month+"-"+day+" "+time[1];
			}
			else if(time[0].contains("-"))
			{
				result = str.substring(0,str.length()-3);
			}
			else
				result = "2015-"+time[0].substring(0,2)+"-"+time[0].substring(3,5)+" "+time[1];
			
			

		}
		
		else
		{
			Calendar ca =Calendar.getInstance();
			 int year = ca.get(Calendar.YEAR);//获取年份
		     int month=ca.get(Calendar.MONTH);//获取月份
		     int day=ca.get(Calendar.DATE);//获取日
		     int hour=ca.get(Calendar.HOUR);//小时 
		     int minute=ca.get(Calendar.MINUTE);//分
		     int m = minute - (str.charAt(0)-'0');
		    
		     result = year+"-"+month+"-"+day+" "+hour+":"+m;
		}
		return result;
	}
}
